package com.eshop.we.service;

import com.alibaba.dubbo.config.annotation.Service;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.eshop.we.leaseorder.api.LeaseOrderService;
import com.eshop.we.leaseorder.entity.LeaseOrder;
import com.eshop.we.leaseorder.enums.StatusEnum;
import com.eshop.we.mapper.LeaseOrderMapper;
import com.eshop.we.utils.DateUtil;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.List;

/**
 * <p>
 * 出租订单 服务实现类
 * </p>
 *
 * @author anonymity
 * @since 2018-07-04
 */
@Service(interfaceClass = LeaseOrderService.class)
@Component
public class LeaseOrderServiceImpl extends ServiceImpl<LeaseOrderMapper, LeaseOrder> implements LeaseOrderService {

    @Override
    public Page<LeaseOrder> selectLeasePage(Page<LeaseOrder> page) {
        page.setCondition(new HashMap<String,Object>(){{
            put("status", StatusEnum.PAYED_NOBACK.getCode()+","+StatusEnum.CONFIRM_BACK.getCode());
        }});
        List<LeaseOrder> orders =  baseMapper.selectLeasePage(page);
        return page.setRecords(orders);
    }

    @Override
    public Page<LeaseOrder> selectIncomePage(Page<LeaseOrder> page) {
        page.setCondition(new HashMap<String,Object>(){{
            put("status", StatusEnum.PAYED_NOBACK.getCode()+","+StatusEnum.CONFIRM_BACK.getCode());
        }});
        List<LeaseOrder> orders =  baseMapper.selectIncomePage(page);
        return page.setRecords(orders);
    }

    @Override
    public Page<LeaseOrder> selectLeaseOrderPage(Page<LeaseOrder> page, String orderNum, String providerName, String consumerName, String startDate, String endDate, Integer status) {
        Long start=null;
        Long end=null;
        try{
            start= startDate!=null? DateUtil.str2Date(startDate+" 00:00:00").getTime():null;
            end= endDate!=null?DateUtil.str2Date(endDate+" 23:59:59").getTime():null;
        }catch (Exception e){
            e.printStackTrace();
        }
        List<LeaseOrder> list= baseMapper.selectLeaseOrderPage(page,orderNum,providerName,consumerName,start,end,status);
        page.setRecords(list);
        return page;
    }
}
